package com.techventus.locations;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class ConfirmDelete extends Activity{

	Button confirmResetButton;
	Button cancelResetButton;
	String locationName = "";
	
	public void onCreate(Bundle bundle) {
		super.onCreate(bundle);
		setRequestedOrientation( ActivityInfo.SCREEN_ORIENTATION_PORTRAIT ); 
		setContentView(R.layout.resetconfirm);
		
		Bundle receivedBundle =getIntent().getExtras();
		locationName =receivedBundle.getString("locationName");
		
		confirmResetButton = (Button)findViewById(R.id.confirmReset);
		cancelResetButton  = (Button)findViewById(R.id.cancelReset);
		
		confirmResetButton.setText("Confirm "+locationName+" Delete");
		
		confirmResetButton.setOnClickListener(confirmResetClick);
		cancelResetButton.setOnClickListener(cancelResetClick);
		

		
		
	}
	
	OnClickListener confirmResetClick = new OnClickListener(){

		@Override
		public void onClick(View v) {
			Toast.makeText(ConfirmDelete.this, "Google Voice Locations is Resetting...", Toast.LENGTH_LONG);
			SQLiteDatabase sql = openOrCreateDatabase("db",0,null);
			
			sql.execSQL("DELETE FROM LOCATIONS WHERE locationName = '"+locationName+"';") ;
			sql.execSQL("DELETE FROM LOCATIONPHONEENABLE WHERE locationName = '"+locationName+"';");
			sql.execSQL("INSERT INTO COMMAND (command) VALUES ('rectify');");
			sql.close();
			ConfirmDelete.this.finish();
		}
		
	};
	
	OnClickListener cancelResetClick = new OnClickListener(){

		@Override
		public void onClick(View arg0) {
			
			ConfirmDelete.this.finish();
		}
		
	};
}
